﻿'这里是附件功能函数模块
Function 翻译英文注解(bb As String) As String
   If Form1.Check1.Value = False Then Return bb
   Dim cc As String = bb, ee As String
   Dim i  As Long, aa As Long
   For i = 1 To Len(cc)
      aa = Asc(cc, i)
      If (aa >= 65 And aa <= 90) Or (aa >= 97 And aa <= 122) Then
         ee = Mid(cc, i)

         ee = TranslateEn(ee)
         ee = StrToUtf8(ee)
         cc = Left(cc, i -1)
         Exit For
      End If
   Next
   Return cc & ee
   
End Function
Function TranslateEn(enText As String) As String '百度翻译接口，由 QQ243303453 逝去的风 提供
   If 百度appid = "" Then Return enText
   Dim i As Long
   If UBound(百度翻译缓存) > -1 Then
      For i = 0 To UBound(百度翻译缓存) Step 2
         If 百度翻译缓存(i) = enText Then
            If i < UBound(百度翻译缓存) Then
               Return 百度翻译缓存(i + 1)
            End If
         End If
      next
   End If
   
   Dim q        As String = enText '要翻译的字符串
   Dim sign     As String = MD5(百度appid & q & 百度salt & 百度key)
   Dim url      As String = "http://api.fanyi.baidu.com/api/trans/vip/translate"
   Dim http     As String = url & "?q=" & Url字符编码(q) & "&from=en&to=zh&appid=" & 百度appid & "&salt=" & 百度salt & "&sign=" & sign
   Dim httpData As String = Http_Post(http, "")
   Dim ff       As Long   = InStr(httpData, "dst"":""")
   If ff = 0 Then Return ""
   httpData = Mid(httpData, ff + 6)
   ff       = InStr(httpData, """")
   httpData = Left(httpData, ff -1)
   
   Dim text As String
   For i = 1 To Len(httpData)
      If Mid(httpData, i, 2) = "\u" Then
         text &= WChr(ValInt("&H" & Mid(httpData, i + 2, 4)))
         i    += 5
      Else
         text &= Mid(httpData, i, 1)
      End If
   Next
   百度翻译缓存更改=1
   i = UBound(百度翻译缓存)
   ReDim Preserve 百度翻译缓存(i + 2)
   百度翻译缓存(i + 1) = enText
   百度翻译缓存(i + 2) = text
      
   Return text
End Function
Sub 处理单行中有注解(ss As String) 
   Dim i As Long, 引号 As Long
   Do
      i += 1
      If i > Len(ss) Then Exit Do
      If Mid(ss, i, 1) = """" Then
         If 引号 = 0 Then 引号 = 1 Else 引号 = 0
      End If
      If 引号 = 0 Then
         If Mid(ss, i, 2) = "//" or  Mid(ss, i, 2) = "/*"  Then
            Mid(ss, i, 2) = "' "
            Dim pp As String = Left(ss, i -1)
            ss = pp & "' " & 翻译英文注解(Mid(ss, i + 2))
            Exit Do
         End If
      End If
   Loop
End Sub

Sub 直接替换关键词(ss As String) '不替换 引号中的 注解中的，关键词必须完全匹配才替换，不会替换某关键词包含的
   Dim i As Long, 双引号 As Long, ti As Long = 1, 单引号 As Long
   Do
      i += 1
      If i > Len(ss) Then
         直接替换关键词2(i, ti, ss)
         Exit Do
      End If
      If 单引号 Then
         If Mid(ss, i, 1) = "'" Then
            ss = Left(ss, i -1) & """)" & Mid(ss, i + 1)
            i+=1
            单引号=0
         End If    
         Continue Do
      End If
      If 双引号 Then
         If Mid(ss, i, 1) = """" Then 双引号=0
         Continue Do
      End If
      
      If Mid(ss, i, 1) = """" Then
         双引号 = 1
         直接替换关键词2(i, ti, ss)
         ti = i + 1
         Continue Do
      End If
      If Mid(ss, i, 1) = "'" Then
         ss =Left(ss, i-1) & "Asc(!""" & Mid(ss,i+1) 
         单引号 = 1
         直接替换关键词2(i, ti, ss)
         ti = i + 1
         Continue Do
      End If      
      
      If 双引号 = 0 And 单引号 = 0 Then
         If Mid(ss, i, 2) = "//" Then Exit Do
         If 直接替换关键词符号(ss, i, "||", " Or ")   Then Continue Do
         If 直接替换关键词符号(ss, i, "&&", " And ")  Then Continue Do
         If 直接替换关键词符号(ss, i, "==", "=")      Then Continue Do
         If 直接替换关键词符号(ss, i, "++", "+=1 ")   Then Continue Do
         If 直接替换关键词符号(ss, i, "--", "-=1 ")   Then Continue Do
         If 直接替换关键词符号(ss, i, "!=", "<>")     Then Continue Do
         If 直接替换关键词符号(ss, i, "%=", " Mod=")  Then Continue Do
         If 直接替换关键词符号(ss, i, " 0x", " &H")   Then Continue Do
         If 直接替换关键词符号(ss, i, "!", " Not ")   Then Continue Do
         'If 直接替换关键词符号(ss, i, "][", ")(")       Then Continue Do
         'If 直接替换关键词符号(ss, i, "[", "(")       Then Continue Do
         'If 直接替换关键词符号(ss, i, "]", ")")       Then Continue Do
         If 直接替换关键词符号(ss, i, "|=", " Or=")   Then Continue Do
         If 直接替换关键词符号(ss, i, "^=", " Xor=")  Then Continue Do
         If 直接替换关键词符号(ss, i, "&=", " And=")  Then Continue Do
         If 直接替换关键词符号(ss, i, "<<=", " Shl=") Then Continue Do
         If 直接替换关键词符号(ss, i, ">>=", " Shr=") Then Continue Do
         If 直接替换关键词符号(ss, i, " & ", " And ") Then Continue Do
         If 直接替换关键词符号(ss, i, "%", " Mod ") Then Continue Do
          If 直接替换关键词符号(ss, i, "&", "@") Then Continue Do
         
         If InStr(" `~!@#$%^&*()[]{}\|+-*/=;:',<>?", Mid(ss, i, 1)) Then
            直接替换关键词2(i, ti, ss)
            ti = i + 1
         End If
      End If
   Loop
End Sub
Function 直接替换关键词符号(ss As String, ByRef i As Long, 被替换 As String, 替换成 As String) As Long
   If Mid(ss, i, Len(被替换)) = 被替换 Then
      ss = Left(ss, i -1) & 替换成 & Mid(ss, i + Len(被替换))
      i  += Len(替换成) -1
   Else
      Return 0
   End If
End Function

Sub 直接替换关键词2(ByRef i As Long, ti As Long, ss As String) '不替换 引号中的 注解中的，关键词必须完全匹配才替换，不会替换某关键词包含的
   If ti < i Then
      Dim u As Long = UBound(直接替换列表关键词c)
      If u = -1 Then Return
      Dim kk As String =( Mid(ss, ti, i - ti))    '  LCase
      Dim ci As Long
      For ci = 0 To u
         If 直接替换列表关键词c(ci) = kk Then
            ss = Left(ss, ti -1) & 直接替换列表关键词b(ci) & Mid(ss, i)
            i  += Len(直接替换列表关键词b(ci)) - Len(直接替换列表关键词c(ci))
            Exit For
         End If
      Next
   End If
End Sub

Sub 加载直接替换列表()
   Dim pp() As String, ss As String
   ss = GetFileStrUtf8(App.Path & "直接替换列表关键词.txt")   
   If Len(ss) Then
      vbSplit(ss, vbCrLf, pp())
      Dim i As Long, u As Long = UBound(pp)
      ReDim 直接替换列表关键词c(u), 直接替换列表关键词b(u)
      dim ff as long
      For i = 0 To UBound(pp)
         pp(i) = Trim(pp(i), Any Chr(32, 13, 10))
         ff    = InStr(pp(i), """""")
         If ff = 0 Then
            If i = 0 Then
               Erase 直接替换列表关键词c, 直接替换列表关键词b
            Else
               ReDim Preserve 直接替换列表关键词c(i -1), 直接替换列表关键词b(i -1)
            end if
            Exit For
         End If
         直接替换列表关键词c(i) =( Mid(pp(i), 2, ff -2)) ' LCase
         直接替换列表关键词b(i) = Mid(pp(i), ff + 2, Len(pp(i)) - ff -2)
      Next
   Else
      Erase 直接替换列表关键词c, 直接替换列表关键词b
   End If
End Sub

Function InStr代码查找结束配对(开始查位置 As Long, 源字符 As String) As Long '查 "}" 不查找注解部分，字符部分
   Dim i As Long = 开始查位置, 配对 As Long, 单引号 As Long, 双引号 As Long, 注解 As Long, 多行注解 As Long
   For i = 开始查位置 To Len(源字符)
      If 单引号 Then
         If Mid(源字符, i, 1) = "'" Then 单引号 = 0
         Continue For
      End If
      If 双引号 Then
         If Mid(源字符, i, 1) = """" Then 双引号 = 0
         Continue For
      End If
      If 注解 Then
         If Mid(源字符, i, 2) = vbCrLf Then
            注解 = 0
            i    += 1
         End If
         Continue For
      End If
      If 多行注解 Then
         If Mid(源字符, i, 2) = "*/" Then
            多行注解 = 0
            i        += 1
         End If
         Continue For
      End If
      If Mid(源字符, i, 1) = "'"  Then 单引号   = 1  : Continue For
      If Mid(源字符, i, 1) = """" Then 双引号   = 1  : Continue For
      If Mid(源字符, i, 2) = "//" Then 注解     = 1  : i += 1 : Continue For
      If Mid(源字符, i, 2) = "/*" Then 多行注解 = 1  : i += 1 : Continue For
      If Mid(源字符, i, 1) = "{"  Then 配对     += 1 : Continue For
      If Mid(源字符, i, 1) = "}" Then
         If 配对 = 0 Then Return i
         配对 -= 1
      End If
   Next
   Function = 0
End Function
Function InStr代码查找(开始查位置 As Long, 源字符 As String, 查找字符 As String, 括号内不查 As Long = 0) As Long '查找  不查找注解部分，字符部分
   Dim i As Long = 开始查位置, 单引号 As Long, 双引号 As Long, 注解 As Long, 多行注解 As Long, 括号配对 As Long
   For i = 开始查位置 To Len(源字符)
      If 单引号 Then
         If Mid(源字符, i, 1) = "'" Then 单引号 = 0
         Continue For
      End If
      If 双引号 Then
         If Mid(源字符, i, 1) = """" Then 双引号 = 0
         Continue For
      End If
      If 多行注解 Then
         If Mid(源字符, i, 2) = "*/" Then
            多行注解 = 0
            i        += 1
         End If
         Continue For
      End If
      If 注解 Then
         If Mid(源字符, i, 2) = vbCrLf Then
            注解 = 0
            i    += 1
         End If
         Continue For
      End If
      
      If Mid(源字符, i, 1) = "'"  Then 单引号 = i : Continue For
      If Mid(源字符, i, 1) = """" Then 双引号 = i : Continue For
      If 括号配对 = 0 And Mid(源字符, i, 2) = "//" And 查找字符 = "//" Then Return i
      If 括号配对 = 0 And Mid(源字符, i, 2) = "/*" And 查找字符 = "/*" Then Return i
      If Mid(源字符, i, 2) = "//" Then 注解     = i : i += 1 : Continue For
      If Mid(源字符, i, 2) = "/*" Then 多行注解 = i : i += 1 : Continue For
      If 括号配对 > 0 Then
         If Mid(源字符, i, 1) = ")" Then 括号配对 -= 1
         If Mid(源字符, i, 1) = "(" Then 括号配对 += 1
         Continue For
      End If
      If 查找字符 = ")" Or 括号内不查 > 0 Then
         If Mid(源字符, i, 1) = "(" Then 括号配对 += 1 : Continue For
      End If
      If 括号配对 = 0 And Mid(源字符, i, Len(查找字符)) = 查找字符 Then
         Return i
      End If
   Next
   
   Function = 0
End Function
Function InStr代码查找倒查(开始查位置 As Long, ByVal 源字符 As String, 查找字符 As String, 括号不查 As Long = 0) As Long '查找  不查找注解部分，字符部分
   Dim i As Long, 单引号 As Long, 双引号 As Long, 注解 As Long, 多行注解 As Long, 括号配对 As Long
   Dim u As Long = 开始查位置
   If u = 0 Then u = Len(源字符)
   '倒查时，必须先查找注解，避免在注解中查找
   For i = 1 To u
      If 单引号 Then
         If Mid(源字符, i, 1) = "'" Then 单引号 = 0
         Continue For
      End If
      If 双引号 Then
         If Mid(源字符, i, 1) = """" Then 双引号 = 0
         Continue For
      End If
      If 多行注解 Then
         If Mid(源字符, i, 2) = "*/" Then
            Mid(源字符, 多行注解, i - 多行注解 + 2) = String(i - 多行注解 + 2, 1)
            多行注解 = 0
            i        += 1
         End If
         Continue For
      End If
      If 注解 Then
         If Mid(源字符, i, 2) = vbCrLf Then
            Mid(源字符, 注解, i - 注解 + 2) = String(i - 注解 + 2, 1)
            注解 = 0
            i    += 1
         End If
         Continue For
      End If
      If Mid(源字符, i, 1) = "'"  Then 单引号   = i : Continue For
      If Mid(源字符, i, 1) = """" Then 双引号   = i : Continue For
      If Mid(源字符, i, 2) = "/*" Then 多行注解 = i : i += 1 : Continue For
      If Mid(源字符, i, 2) = "//" Then 注解     = i : i += 1 : Continue For
   Next
   If 多行注解 Then
      Mid(源字符, 多行注解, u - 多行注解 + 1) = String(u - 多行注解 + 1, 1)
   End If
   If 注解 Then
      Mid(源字符, 注解, u - 注解 + 1) = String(u - 注解 + 1, 1)
   End If
   
   For i = u To 1 Step -1
      If 单引号 Then
         If Mid(源字符, i, 1) = "'" Then 单引号 = 0
         Continue For
      End If
      If 双引号 Then
         If Mid(源字符, i, 1) = """" Then 双引号 = 0
         Continue For
      End If
      
      If Mid(源字符, i, 1) = "'"  Then 单引号 = 1 : Continue For
      If Mid(源字符, i, 1) = """" Then 双引号 = 1 : Continue For
      If 括号配对 > 0 Then
         If Mid(源字符, i, 1) = "(" Then 括号配对 -= 1
         If Mid(源字符, i, 1) = ")" Then 括号配对 += 1
         Continue For
      End If
      If (括号不查 <> 0 Or 查找字符 = "(") And Mid(源字符, i, 1) = ")" Then 括号配对 += 1 : Continue For
      If 括号配对 = 0 Then 
         If Mid(源字符, i, Len(查找字符)) = 查找字符 Then    Return i
      End If
   Next
   Function = 0
End Function
Function InStr代码查找注解(开始查位置 As Long, 源字符 As String) As Long '查找后面有无注解，跳过空格
   Dim i As Long = 开始查位置
   For i = 开始查位置 To Len(源字符)
      If Mid(源字符, i, 1) = " "  Then Continue For
      If Mid(源字符, i, 2) = "//" Then Return i
      Return 0
   Next
   Function =0 
End Function

Function 变量定义处理(ByVal ss As String) As String
   Dim ff As Long, pp() As String, pi As Long, 空 As Long 
   ss=YF_Replace(ss,vbCrLf,"") 
   空 = Len(ss)
   ss=LTrim(ss, Any Chr(32, 13, 10))
   空 -=Len(ss) 
   Do '分割
      ff = InStr(ss, " ")
      If ff = 0 Then
         If Len(ss) Then
            pi = UBound(pp) + 1
            ReDim Preserve pp(pi)
            pp(pi) = ss
         End If
         Exit Do
      End If
      Dim bb As String = Left(ss, ff -1)
      If Len(bb)>0 And bb<>vbCrLf Then
         pi = UBound(pp) + 1
         ReDim Preserve pp(pi)
         pp(pi) = bb
      End If
      ss = Mid(ss, ff + 1)
   Loop
   If UBound(pp) = -1 Then Return ""
   Dim i As Long, U As String, C As String ,类型 As String ,变量名 As String,指针 As String  
   For i = 0 To UBound(pp)
      If pp(i) = "unsigned" Then
         U = "U"
         Continue For
      End If
      If pp(i) = "const" Then
         C = "Const "
         Continue For
      End If
      If 类型="" Then 
         类型 = pp(i)
      Else
         变量名=pp(i)
      End If 
   Next
   Do 
      If Left(变量名, 1) <> "*" Then Exit Do 
      指针 &= " Ptr"
      变量名 = Mid(变量名, 2)
   Loop 
   For i = 1 To Len(变量名)
      If Mid(变量名, i, 1) = "[" Then 
         Mid(变量名, i, 1) = "("
      ElseIf Mid(变量名, i, 1) = "]" Then
         Mid(变量名, i, 1) = ")"
      End If    
   Next   
   变量名 = YF_Replace(变量名, ")(", ",")
   If 指针 <> "" And 类型 = "char" And U = "" Then 类型 = "ZString"
   If 指针 = "" And 类型 = "char" And InStr(变量名, "(") > 0 Then 
      '这是一个字符串
      ff = InStr(变量名, ",")
      If ff Then '是字符串数组
         Dim xx As String = Mid(变量名, ff + 1)
         变量名=Left(变量名,ff-1) & ")"
         ff = InStr(xx, ")")
         xx = Left(xx, ff -1)
         类型 = "ZString * " & xx
      Else
         ff = InStr(变量名, "(")
         Dim xx As String = Mid(变量名, ff + 1)
         变量名 = Left(变量名, ff -1)
         ff = InStr(xx, ")")
         If ff Then xx=Left(xx,ff-1)
         类型 = "ZString * " & xx         
      End If 
   End If    
   直接替换关键词(类型)
   直接替换关键词(变量名)
   Function =Space(空) &   C & 变量名 & " As " & U & 类型 & 指针    
   
End Function

Function 处理参数列表(ByVal 参数列 As String, 参数前缀 As String) As String
   Dim ff       As Long, ss           As String, 返回     As String
   Dim 变量名() As String, 变量定义() As String, 无符号() As String, 不可修改() As String, 等号() As String, 注解() As String, bi As Long = -1
   Do
      ff = InStr代码查找(1, 参数列, ",", 1)
      If ff = 0 Then
         ss     = 参数列
         参数列 = ""
      Else
         ss     = Left(参数列, ff -1)
         参数列 = Mid(参数列, ff + 1) ', Any Chr(32, 13, 10))
      End If
      bi += 1
      ReDim Preserve 变量名(bi), 变量定义(bi), 无符号(bi), 不可修改(bi), 等号(bi), 注解(bi)
      Dim sf As Long, rr As String
      sf = InStr首字符查找(1, 参数列, "", 0)
      'Print ss
      If sf Then
         If Mid(参数列, sf, 2) = "//" Then
            sf = InStr(sf, 参数列, vbCrLf)
            If sf = 0 Then sf = Len(参数列) + 1
            注解(bi) = Left(参数列, sf - 1)
            参数列   = Mid(参数列, sf + 2)
            处理单行中有注解(注解(bi))
            注解(bi) &= vbCrLf
         ElseIf Mid(参数列, sf, 2) = "/*" Then
            sf = InStr(sf, 参数列, "*/")
            If sf = 0 Then sf = Len(参数列) + 1
            注解(bi) = Left(参数列, sf -1)
            参数列   = Mid(参数列, sf + 2)
            处理单行中有注解(注解(bi))
         End If
      End If
      sf = InStr代码查找(1, ss, "//", 0)
      If sf Then
         注解(bi) &= Mid(ss, sf)
         ss       = Left(ss, sf -1)
         sf       = InStr(sf, 注解(bi), vbCrLf)
         If sf Then 注解(bi) = Left(注解(bi), sf -1)
         处理单行中有注解(注解(bi))
      End If
      sf = InStr代码查找(1, ss, "/*", 0)
      If sf Then
         注解(bi) &= Mid(ss, sf)
         ss       = Left(ss, sf -1)
         sf       = InStr(注解(bi), "*/")
         If sf Then 注解(bi) = Left(注解(bi), sf -1)
         处理单行中有注解(注解(bi))
      End If
      'print ss
      ss = Trim(ss, Any Chr(32, 13, 10))
      If 注解(bi) <> "" Then 注解(bi) &= vbCrLf
      sf = InStr代码查找倒查(0, ss, "=", 1)
      If sf Then
         等号(bi) = " = " & C代码转换B代码(Trim(Mid(ss, sf + 1), Any Chr(32, 13, 10)) & ";")
         ss       = Left(ss, sf -1) ', Any Chr(32, 13, 10))
      End If
      'Print ss
      Dim 方阔 As Long, 单引号 As Long, 双引号 As Long
      Do
         方阔 = 0
         For sf = Len(ss) To 1 Step -1
            If 单引号 Then
               If Mid(ss, sf, 1) = "'" Then 单引号 = 0
               Continue For
            End If
            If 双引号 Then
               If Mid(ss, sf, 1) = """" Then 双引号 = 0
               Continue For
            End If
            If 方阔 = 2 Then
               If Mid(ss, sf, 1) = "[" Then 方阔 = 1
               Continue For
            End If
            If 方阔 = 1 Then
               If Mid(ss, sf, 1) = "]" Then
                  方阔 = 2
               Else
                  If Mid(ss, sf, 1) <> " " Then 方阔 = 0
               End If
               Continue For
            End If
            If Mid(ss, sf, 1) = "'"  Then 单引号 = 1 : Continue For
            If Mid(ss, sf, 1) = """" Then 双引号 = 1 : Continue For
            If Mid(ss, sf, 1) = " "  Then Exit For
            If Mid(ss, sf, 1) = "]"  Then 方阔 = 2
            If Mid(ss, sf, 1) = "["  Then 方阔 = 1
         Next
         If sf = 0 Then
            rr = ss
            ss = ""
         Else
            rr = Trim(Mid(ss, sf), Any Chr(32, 13, 10))
            ss = Trim(Left(ss, sf -1), Any Chr(32, 13, 10))
         End If
         If 变量名(bi) = "" Then
            变量名(bi) = rr
         Else
            If 变量定义(bi) = "" Then
               If rr = "*" Or rr = ">" Or rr = "=" Then
                  变量名(bi) = rr & 变量名(bi)
                  
               Else
                  Do
                     If Right(rr, 1) <> "*" Then Exit Do
                     变量名(bi) = "*" & 变量名(bi)
                     rr         = Left(rr, Len(rr) -1)
                  Loop
                  If InStr("[]<>!@#$%^&*(=,./?\|+-`~", Right(rr, 1)) > 0 Or InStr("[]<>!@#$%^&*(=,./?\|+-`~", Left(rr, 1)) > 0 Then '不是变量定义了
                     变量名(bi) = ss & " " & rr & " " & 变量名(bi)
                     Exit Do
                  Else
                     变量定义(bi) = rr
                  End If
               End If
            Else
               If rr = "unsigned" Then 无符号(bi)   = "U"
               If rr = "const"    Then 不可修改(bi) = "Const "
            End If
         End If
         If sf = 0 Then Exit Do
      Loop
      Do
         If Left(变量名(bi), 1) <> "*" Then Exit Do
         If 变量定义(bi) = ""          Then Exit Do
         变量名(bi) = Mid(变量名(bi), 2)
         If 变量定义(bi) = "char" And 无符号(bi) = "" Then 变量定义(bi) = "ZString"
         变量定义(bi) &= " Ptr"
      Loop
      If 变量定义(bi) = "char" And Right(变量名(bi), 1) = "]" Then
         Dim tf As Long = InStr(变量名(bi), "[")
         If tf Then
            变量定义(bi) = "ZString * " & Mid(变量名(bi), tf + 1, Len(变量名(bi)) - tf -1)
            变量名(bi)   = Left(变量名(bi), tf -1)
         End If
      End If
      直接替换关键词(变量定义(bi))
      '直接替换关键词(变量名(bi))
      
      If ff = 0 Then Exit Do
   Loop
   If bi > -1 Then
      For ff = 0 To bi
         If ff < bi And bi > 0 Then 等号(ff) &= ","
         If 注解(ff) <> ""     Then 等号(ff) &= " _ "
         'Print ff,变量名(ff) , 不可修改(ff) , 无符号(ff) , 变量定义(ff) , 等号(ff) , 注解(ff)
         If Len(变量定义(ff)) = 0 Then
            
            返回 &= 变量名(ff) & 等号(ff)
         Else
            If Right(变量名(ff), 1) = "]" And Right(变量名(ff), 2) <> "[]" Then 变量名(ff) = Left(变量名(ff), Len(变量名(ff)) -1) & " -1]" 
            变量名(ff) = YF_Replace(变量名(ff), "]", ")")
            变量名(ff) = YF_Replace(变量名(ff), "[", "(")
            变量名(ff) = YF_Replace(变量名(ff), ")(", ",")
            
            返回 &= 参数前缀 & 变量名(ff) & " As " & 不可修改(ff) & 无符号(ff) & 变量定义(ff) & 等号(ff) & 注解(ff)
         End If
      Next
   end if
   Function = 返回
End Function
Sub 未处理代码处理(ci As Long , B代码 As String, 未处理代码 As String)
   If Len(未处理代码) Then
      Dim ss As String  = 未处理代码
      直接替换关键词(未处理代码)
      新增翻译列表("未处",ci, ss,Len(B代码)+1, 未处理代码)
      B代码 &= 未处理代码      
      未处理代码 = ""
   End If
End Sub

Function InStr首字符查找(开始查位置 As Long, 源字符 As String, 查找字符 As String, 括号内不查 As Long) As Long '查找 遇到的第一个字符，是不是我们需要的字符,查找字符="" 则任意字符，跳过空格和换行
   Dim i As Long = 开始查位置, 单引号 As Long, 双引号 As Long, 注解 As Long, 多行注解 As Long, 括号配对 As Long
   For i = 开始查位置 To Len(源字符)
      If 括号内不查 Then
         If 括号配对 Then
            If Mid(源字符, i, 1) = ")" Then 括号配对 -= 1
            Continue For
         End If
      End If
      If Mid(源字符, i, 1) = " "  Then Continue For
      If Mid(源字符, i, 1) = vbCr Then Continue For
      If Mid(源字符, i, 1) = vbLf Then Continue For
      If 括号内不查 Then
         If Mid(源字符, i, 1) = "(" Then
            括号配对 += 1
            Continue For
         End If
      End If
      If 括号配对 = 0 Then
         If 查找字符 = "" Then Return i
         If Mid(源字符, i, Len(查找字符)) = 查找字符 Then Return i
         Return 0
      End If
      'Print i,Asc(源字符,i), Mid(源字符, i, 1) , 查找字符
   Next
   Function = 0
End Function
Function InStr首字符查找倒查(开始查位置 as Long, 源字符 as String, 查找字符 as String, 括号内不查 as Long) as Long '查找  遇到的第一个字符，是不是我们需要的字符,查找字符="" 则任意字符，跳过空格和换行
   Dim i As Long, k As Long = 开始查位置, 单引号 As Long, 双引号 As Long, 注解 As Long, 多行注解 As Long, 括号配对 As Long
   If k = 0 Then k = Len(源字符)
   For i = k To 1 Step -1
      If 括号内不查 Then
         If 括号配对 Then
            If Mid(源字符, i, 1) = "(" Then 括号配对 -= 1
            Continue For
         End If
      End If
      If Mid(源字符, i, 1) = " "  Then Continue For
      If Mid(源字符, i, 1) = vbCr Then Continue For
      If Mid(源字符, i, 1) = vbLf Then Continue For
      If 括号内不查 Then
         If Mid(源字符, i, 1) = ")" Then
            括号配对 += 1
            Continue For
         End If
      End If
      If 括号配对 = 0 Then
         If 查找字符 = "" Then Return i
         If Mid(源字符, i, Len(查找字符)) = 查找字符 Then Return i
         Return 0
      End If
   Next
   Function = 0
End Function
Function InStr运算符查找倒查(开始查位置 As Long, 源字符 As String) As Long '查找  遇到的第一个符号字符
   Dim i As Long, 单引号 As Long, 双引号 As Long, 注解 As Long, 多行注解 As Long, 括号配对 As Long
   Dim u As Long = 开始查位置, cc As String, kk As Long
   If u = 0 Then u = Len(源字符)
   For i = u To 1 Step -1
      If 单引号 Then
         If Mid(源字符, i, 1) = "'" Then 单引号 = 0
         Continue For
      End If
      If 双引号 Then
         If Mid(源字符, i, 1) = """" Then 双引号 = 0
         Continue For
      End If
      If 多行注解 Then
         If Mid(源字符, i, 2) = "/*" Then
            多行注解 = 0
            i        -= 1
         End If
         Continue For
      End If
      
      If Mid(源字符, i, 1) = "'"  Then 单引号   = 1 : Continue For
      If Mid(源字符, i, 1) = """" Then 双引号   = 1 : Continue For
      If Mid(源字符, i, 2) = "*/" Then 多行注解 = 1 : i += 1 : Continue For
      If Mid(源字符, i, 1) = "(" Then 括号配对 -= 1 : Continue For
      If Mid(源字符, i, 1) = ")" Then 括号配对 += 1 : Continue For
      If 括号配对 <= 0 Then
         kk = 0
         cc = Mid(源字符, i -3, 2)
         If cc = ">>=" Or cc = "<<=" Then kk = 3
         If kk = 0 Then
            cc = Mid(源字符, i -1, 2)
            If cc = "&&" Or cc = "||" Or cc = "==" Or cc = "!=" Or cc = ">=" Or cc = "<=" Or cc = "|=" Or cc = "<<" Or _
               cc = "+=" Or cc ="*=" Or cc = "-=" Or cc = "/=" Or cc = "%=" Or cc = "&="  Or cc = "^="   Or cc = ">>"  Then kk = 2
            End If
         If cc = "->" then
            i -= 1
            Continue For
            
         End If
         If kk = 0 Then
            cc = Mid(源字符, i, 1)
            If cc = ">" Or cc = "<" Or cc = "!" Or cc = "+" Or cc = "-" Or cc = "*" Or cc = "/" Or cc = "%" Or _
               cc = "&"  Or cc = "|"  Or cc = "^"  Or cc = "~" Or cc = "="   Then kk = 1
            End If
         If kk Then Return i - (kk -1)
      End If
   Next
   Function = 0
End Function
Function InStr不是运算符查找(开始查位置 as Long, 源字符 as String) as Long '查找  遇到的第一个符号字符
   Dim i As Long = 开始查位置, 单引号 As Long, 双引号 As Long, 注解 As Long, 多行注解 As Long, 括号配对 As Long
   Dim u As Long, cc As String, kk As Long
   If u = 0 Then u = Len(源字符)
   For i =开始查位置  To u
      cc = Mid(源字符, i , 1)
      If InStr(">=&|!<+-*/%&^~",cc)=0 Then Return i 
   Next
   Function = 0
End Function

Sub 变量列表连续变量(ss As String)
   Dim aff  As Long = 1, ff as long
   Dim bb   As String, pss  As String
   Dim 等号 as String, 类型 as String, nn as String
   '把连续声明的类型放前面，要是遇到一行中连续声明还搞不同类型的话就有问题
   ff = InStr代码查找(1, ss, ",", 1)
   if ff then
      aff = InStr代码查找(1, ss, " As ", 1)
      If aff Then
         Dim dd As String = Left(ss, ff -1)
         Dim df As Long = InStr代码查找(1, dd, "=",1)
         If df Then 
            ss = Mid(ss, aff + 1, df - aff -1) & " " & Left(ss, aff -1) & Mid(ss, df)
         Else 
            ss = Mid(ss, aff + 1, ff - aff -1) & " " & Left(ss, aff -1) & Mid(ss, ff)
         End If 
      End If
   End If
   '遇到有连续声明，没类型的，增加为前面的类型，这样支持一行中连续声明还支持不同类型
   'Do
   '   aff = InStr代码查找(1, ss, ",", 1)
   '   If aff Then
   '      bb = Left(ss, aff -1)
   '      ss = Mid(ss, aff + 1)
   '   Else
   '      bb = ss
   '      ss = ""
   '   End If
   '   ff = InStr代码查找(1, bb, "=", 1)
   '   If ff Then
   '      等号 = Mid(bb, ff)
   '      bb   = Left(bb, ff -1)
   '   Else
   '      等号 = ""
   '   End If
   '   ff = InStr代码查找(1, bb, " As ", 1)
   '   If ff Then
   '      nn = Trim(Mid(bb, ff + 4))
   '      'bb=
   '      If nn = "Ptr" Then
   '         If Len(pss) Then pss &= ","
   '         pss &= Left(bb,ff-1) & " As " & 类型 & " Ptr" & 等号
   '      Else
   '         类型 = nn
   '         If Len(pss) Then pss &= ","
   '         pss &= bb & 等号
   '      end if
   '   Else
   '      If Len(pss) Then pss &= ","
   '      pss &= bb & " As " & 类型 & 等号
   '   end if
   '   If aff = 0 Then Exit Do
   'Loop
   'ss = pss
End Sub
Function InStr空字符查找(开始查位置 As Long, 源字符 As String, 括号内不查 As Long) As Long '查找 遇到的第一个空字符（空格和换行）
   Dim i As Long = 开始查位置, 单引号 As Long, 双引号 As Long, 注解 As Long, 多行注解 As Long, 括号配对 As Long
   For i = 开始查位置 To Len(源字符)
      'Print i,Asc(源字符,i),Mid(源字符,i,1)
      If 括号内不查 Then
         If 括号配对 Then
            If 单引号 Then
               If Mid(源字符, i, 1) = "'" Then 单引号 = 0
               Continue For
            End If
            If 双引号 Then
               If Mid(源字符, i, 1) = """" Then 双引号 = 0
               Continue For
            End If
            If Mid(源字符, i, 1) = "'"  Then 单引号 = 1 : Continue For
            If Mid(源字符, i, 1) = """" Then 双引号 = 1 : Continue For
            
            If Mid(源字符, i, 1) = ")" Then 括号配对 -= 1
         End If
      End If
      
      If 括号内不查 Then
         If Mid(源字符, i, 1) = "(" Then
            括号配对 += 1
            Continue For
         End If
         
      End If
      If 括号配对 = 0 Then
         If Mid(源字符, i, 1) = " "  Then Return i
         If Mid(源字符, i, 1) = vbCr Then Return i
         If Mid(源字符, i, 1) = vbLf Then Return i
         If Mid(源字符, i, 1) = ")" Then Return i '有的语句括号后不写空格，遇到括号结尾就结束了。
      end if
   Next
   Function = Len(源字符) + 1
End Function
Function InStr空字符查找倒查(开始查位置 as Long, 源字符 as String, 括号内不查 as Long) as Long '查找 遇到的第一个空字符（空格和换行）
   Dim i As Long, 单引号 As Long, 双引号 As Long, 注解 As Long, 多行注解 As Long, 括号配对 As Long
   Dim u As Long = 开始查位置
   If u = 0 Then u = Len(源字符)
   For i = u To 1 Step -1
      'Print i,Asc(源字符,i),Mid(源字符,i,1)
      If 括号内不查 Then
         If 括号配对 Then
            If 单引号 Then
               If Mid(源字符, i, 1) = "'" Then 单引号 = 0
               Continue For
            End If
            If 双引号 Then
               If Mid(源字符, i, 1) = """" Then 双引号 = 0
               Continue For
            End If
            If Mid(源字符, i, 1) = "'"  Then 单引号 = 1 : Continue For
            If Mid(源字符, i, 1) = """" Then 双引号 = 1 : Continue For
            
            If Mid(源字符, i, 1) = "(" Then 括号配对 -= 1
         End If
      End If
      
      If 括号内不查 Then
         If Mid(源字符, i, 1) = ")" Then
            括号配对 += 1
            Continue For
         End If
         
      End If
      If 括号配对 = 0 Then
         If Mid(源字符, i, 1) = " "  Then Return i
         If Mid(源字符, i, 1) = vbCr Then Return i
         If Mid(源字符, i, 1) = vbLf Then Return i
         If Mid(源字符, i, 1) = "("  Then Return i '有的语句括号后不写空格，遇到括号结尾就结束了。
      End If
   Next
   Function = 1
End Function
Sub 强制类型转换(ss As String) '检查是否包含强制类型转换，就添加
   '(byte)aaa  Cast(Byte,aaa)
   Dim i As Long, 单引号 As Long, 双引号 As Long, 注解 As Long, 多行注解 As Long, 括号配对 As Long, 括号起点 As Long
   Do
      i += 1
      If i > Len(ss) Then Exit Do
      If 单引号 Then
         If Mid(ss, i, 1) = "'" Then 单引号 = 0
         Continue Do
      End If
      If 双引号 Then
         If Mid(ss, i, 1) = """" Then 双引号 = 0
         Continue Do
      End If
      If 多行注解 Then
         If Mid(ss, i, 2) = "/*" Then
            多行注解 = 0
            i        -= 1
         End If
         Continue Do
      End If
      
      If Mid(ss, i, 1) = "'"  Then 单引号   = 1 : Continue Do
      If Mid(ss, i, 1) = """" Then 双引号   = 1 : Continue Do
      If Mid(ss, i, 2) = "*/" Then 多行注解 = 1 : i += 1 : Continue Do
      If 括号配对 > 0 Then
         If Mid(ss, i, 1) = ")" Then ' Or Mid(ss, i, 1) = "]" 
            括号配对 -= 1
            If 括号起点 > 0 Then
               Dim pp As String = Mid(ss, 括号起点, i - 括号起点 + 1)
               pp = YF_Replace(pp, " ", "")
               If pp = "()" Then 括号起点 = 0 : Continue Do
               Dim ii As Long, jj As Long
               For ii = 2 To Len(pp) -1
                  If ii = 0 Then '开头不允许有数字
                     If InStr("._abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", Mid(pp, ii, 1)) = 0 Then Exit For
                     jj += 1
                  ElseIf ii = Len(pp) -1 Then '最后一个字符才允许有 *
                     If InStr("._abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890*", Mid(pp, ii, 1)) = 0 Then Exit For
                     jj += 1
                  Else
                     If InStr("._abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", Mid(pp, ii, 1)) = 0 Then Exit For
                     jj += 1
                  End If
               Next
               If jj = Len(pp) -2 Then '符合强制类型转换的条件1
                  jj = InStr首字符查找(i + 1, ss, "", 0)
                  If jj Then
                     If InStr("._abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ([", Mid(ss, jj, 1)) > 0 Then
                        Dim ff As Long
                        If Mid(ss, jj, 1) = "(" Then
                           ff = InStr代码查找(jj + 1, ss, ")", 1)
                           If ff = 0 Then ff = Len(ss)
                           ff += 1
                        ElseIf Mid(ss, jj, 1) = "[" Then
                           ff = InStr代码查找(jj + 1, ss, "]", 1)
                           If ff = 0 Then ff = Len(ss)
                           ff += 1
                        Else
                           ff = InStr非关键词(jj + 1, ss)
                           If ff = 0 Then ff = Len(ss)
                           Dim kf As Long = InStr首字符查找(ff, ss, "", 0)
                           If Mid(ss, kf, 1) = "(" Then
                              ff = InStr代码查找(kf + 1, ss, ")", 1)
                              If ff = 0 Then ff = Len(ss) Else ff+=1
                           End If
                           If Mid(ss, kf, 1) = "[" Then
                              ff = InStr代码查找(kf + 1, ss, "]", 1)
                              If ff = 0 Then ff = Len(ss)  Else ff+=1
                           End If
                           
                           If Mid(ss, ff, 1) = "." Then
                              ff = InStr非关键词(ff + 1, ss)
                              If ff = 0 Then ff = Len(ss)
                           ElseIf Mid(ss, ff, 2) = "->" Then
                              ff = InStr非关键词(ff + 2, ss)
                              If ff = 0 Then ff = Len(ss)
                           End If
                        End If
                        pp = Mid(pp, 2, Len(pp) -2)
                        
                        Dim zz As String
                        Do
                           If Right(pp, 1) <> "*" Then Exit Do
                           zz &= " Ptr"
                           pp = Left(pp, Len(pp) -1)
                        Loop

                        ss = Left(ss, 括号起点 -1) & "Cast(" & pp & zz & "," & Mid(ss, i + 1, ff - i -1) & ")" & Mid(ss, ff)
                        i  = 括号起点 + Len("Cast(" & pp & zz & "," & Mid(ss, i + 1, ff - i -1) & ")")
                     End If
                  End If
               End If
               括号起点 = 0
            End If
            Continue Do
         End If
      End If
      If Mid(ss, i, 1) = "("  Then ' Or Mid(ss, i, 1) = "["
         括号配对 += 1
         括号起点 = i
         Continue Do
      End If
   Loop
   
End Sub

Function InStr非关键词(开始查位置 as Long, 源字符 as String) as Long '查找 遇到的第一个非关键字符
   Dim i as Long, ff as Long, 成员 as Long
   For i = 开始查位置 To Len(源字符)
      'Print i,Asc(源字符,i),Mid(源字符,i,1)
      If InStr("._abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ", Mid(源字符, i, 1)) = 0 Then
         If Mid(源字符, i, 2) = "->" Then
            成员 = 1
            i    += 1
         Else
            If Mid(源字符, i, 1) = " " Or Mid(源字符, i, 1) = Chr(10) Or Mid(源字符, i, 1) = Chr(13) Then
               If 成员 Then
                  Continue For
               Else
                  '有空格，可能后面是 小数点，类成员，是一个整体
                  ff = InStr首字符查找(i, 源字符, "", 0)
                  If ff Then
                     If Mid(源字符, ff, 1) = "." Then
                        成员 = 1
                        i    = ff
                        Continue For
                     End If
                     If Mid(源字符, ff, 2) = "->" Then
                        成员 = 1
                        i    = ff +1
                        Continue For
                     End If
                  End If
               End If
            End If
            Return i
         End If
      Else
         If Mid(源字符, i, 1) = "." Then 成员 = 1 Else 成员 = 0
      End If
   Next
   Function = Len(源字符) + 1
End Function
Function InStr非关键词倒查(开始查位置 as Long, 源字符 as String) as Long '查找 遇到的第一个非关键字符
   Dim i as Long, ff as Long, 成员 as Long
   If 开始查位置=0 Then 开始查位置=Len(源字符)
   For i = 开始查位置 To 1 Step -1
      'Print i,Asc(源字符,i),Mid(源字符,i,1)
      If InStr("._abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ", Mid(源字符, i, 1)) = 0 Then
         If Mid(源字符, i-1, 2) = "->" Then
            成员 = 1
            i    -= 1
         Else
            If Mid(源字符, i, 1) = " " Or Mid(源字符, i, 1) = Chr(10) Or Mid(源字符, i, 1) = Chr(13) Then
               If 成员 Then
                  Continue For
               Else
                  '有空格，可能后面是 小数点，类成员，是一个整体
                  ff = InStr首字符查找倒查(i, 源字符, "", 0)
                  If ff Then
                     If Mid(源字符, ff, 1) = "." Then
                        成员 = 1
                        i    = ff
                        Continue For
                     End If
                     If Mid(源字符, ff-1, 2) = "->" Then
                        成员 = 1
                        i    = ff -1
                        Continue For
                     End If
                  End If
               End If
            End If
            Return i
         End If
      Else
         If Mid(源字符, i, 1) = "." Then 成员 = 1 Else 成员 = 0
      End If
   Next
   Function = 0
End Function
Function InStr关键词(开始查位置 as Long, 源字符 as String) as Long '查找 遇到的第一个关键字符
   Dim i as Long
   For i = 开始查位置 To Len(源字符)
      'Print i,Asc(源字符,i),Mid(源字符,i,1)
      If InStr("._abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ", Mid(源字符, i, 1)) > 0 Then
         Return i
      Else
         If Mid(源字符, i, 2) = "->" Then Return i
      End If
   Next
   Function = Len(源字符) + 1
End Function
Function InStr关键词倒查(开始查位置 as Long, 源字符 as String) as Long '查找 遇到的第一个关键字符
   Dim i as Long, ff as Long, 成员 as Long
   If 开始查位置=0 Then 开始查位置=Len(源字符)
   For i = 开始查位置 To 1 Step -1
      'Print i,Asc(源字符,i),Mid(源字符,i,1)
      If InStr("._abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ", Mid(源字符, i, 1)) > 0 Then
         Return i
      Else
         If Mid(源字符, i-1, 2) = "->" Then Return i
      End If
   Next
   Function = 0
End Function

Function 处理函数参数(ByVal 参数列 As String) As String
   Dim ff       As Long, ss           As String, 返回     As String
   Dim 变量名() As String, 变量定义() As String, 无符号() As String, 不可修改() As String, 等号() As String, 注解() As String, bi As Long = -1
   Do
      ff = InStr代码查找(1, 参数列, ",", 1)
      If ff = 0 Then
         ss     = 参数列
         参数列 = ""
      Else
         ss     = Left(参数列, ff -1)
         参数列 = Mid(参数列, ff + 1) ', Any Chr(32, 13, 10))
      End If
      If 返回 <> "" Then 返回 &= ","
      'Print ss
      强制类型转换(ss)
      返回 &= C代码转换B代码(ss & ";")
      If ff = 0 Then Exit Do
   Loop
   Function = 返回
End Function

















